<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>机构管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.control-group{
			width:55%;
		}
	</style>
	<script type="text/javascript">
	$(document).ready(function() {
		$("#name").focus();
		$("#inputForm").validate({
			rules:{
            	name: {remote: "${ctx}//sys/office/isName?oldName=" + encodeURIComponent('${office.name}')},
            	loginName: {remote: "${ctx}/sys/user/checkLoginName?oldLoginName=" + encodeURIComponent('${office.loginName}')},
                contactsPhone:{ 
                	checkContactsPhone:true,
                },
                phone:{ 
                	checkPhone:true,
                }
            },
            messages: {
				loginName: {remote: "用户登录名已存在"},
				name:{remote: "代理商/个人名称已存在"}
			},
			submitHandler: function(form){
				loading('正在提交，请稍等...');
				form.submit();
			},
			errorContainer: "#messageBox",
			errorPlacement: function(error, element) {
				$("#messageBox").text("输入有误，请先更正。");
				if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
					error.appendTo(element.parent().parent());
				} else {
					error.insertAfter(element);
				}
			}
		});
		 $.validator.addMethod("checkContactsPhone",function(value,element,params){ 
	            var phone = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/;  
	            return this.optional(element)||(phone.test(value));  
	        },"请输入正确的11位手机号码！");
		    $.validator.addMethod("checkPhone",function(value,element,params){ 
	            var phone = /^[\d\-]+$/;  
	            return this.optional(element)||(phone.test(value));  
	        },"请输入正确的手机或者电话格式号码！");
	});
		//代理商类型选择隐藏
		function choiceType(){
			var type = $("#type").val();
			if(type == 1){//企业的信息
				$("#agentDiv").show();
			}else{
				$("#agentDiv").hide();
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/office/list">代理商列表</a></li>
		<shiro:hasPermission name="sys:office:save">
			<li class="active">
				<a href="${ctx}/sys/office/form?id=${office.id}&types=1">代理商增加</a>
			</li>
		</shiro:hasPermission>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="office" action="${ctx}/sys/office/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
			<div class="control-group">
				<label class="control-label">上级代理商:</label>
				<div class="controls">
	                <input type="hidden" name="parent.id" value="${parId}"/>
					<input class="input-xlarge" style="border: 1px solid #ccc;padding: 4px 6px;" value="${officeParName}" readonly="readonly">
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">代理商类型:</label>
				<div class="controls">
					<select id="type" onclick="choiceType()">
						<option value="1">代理商</option>
						<option value="2">个人</option>
					</select>
					<span class="help-inline"><font color="red">*</font></span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">代理商/个人名称:</label>
				<div class="controls">
					<form:input path="name" htmlEscape="false" maxlength="20" class="required"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">登录名:</label>
				<div class="controls">
					<input id="oldLoginName" name="oldLoginName" type="hidden" value="${user.loginName}">
					<form:input path="loginName" htmlEscape="false" maxlength="10" class="required userName"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">密码:</label>
				<div class="controls">
					<input id="newPassword" name="newPassword" type="password" value="" maxlength="20" minlength="3" class="${empty user.id?'required':''}"/>
					<c:if test="${empty user.id}"><span class="help-inline"><font color="red">*</font> </span></c:if>
					<c:if test="${not empty user.id}"><span class="help-inline">若不修改密码，请留空。</span></c:if>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">确认密码:</label>
				<div class="controls">
					<input id="confirmNewPassword" name="confirmNewPassword" type="password" value="" maxlength="20" minlength="3" equalTo="#newPassword"/>
					<c:if test="${empty user.id}"><span class="help-inline"><font color="red">*</font> </span></c:if>
				</div>
			</div>
			<!-- 企业信息 -->
			<div id="agentDiv">
				<div class="control-group">
					<label class="control-label">企业注册地址:</label>
					<div class="controls">
						<form:input path="address" htmlEscape="false" class="required" maxlength="20"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">企业注册号:</label>
					<div class="controls">
						<form:input path="bussregNo" htmlEscape="false" class="required" maxlength="20"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">营业执照失效时间:</label>
					<div class="controls">
						<form:input path="expirtTime" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate required date"
						onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">法人姓名:</label>
					<div class="controls">
						<form:input path="contactsName" htmlEscape="false" class="required" maxlength="20"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">法人手机号:</label>
					<div class="controls">
						<form:input path="contactsPhone"  htmlEscape="false" class="required" maxlength="11"/>
						<span class="help-inline"><font color="red">*</font> </span>
					</div>
				</div>
			</div>
			<!-- END -->
			<div class="control-group">
				<label class="control-label">联系电话:</label>
				<div class="controls">
					<form:input path="phone" htmlEscape="false" maxlength="20"/>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">邮箱:</label>
				<div class="controls">
					<form:input path="email" htmlEscape="false" maxlength="20" class="email"/>
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">卡号:</label>
				<div class="controls">
					<form:input path="cardNo" class="required" htmlEscape="false" maxlength="30"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">持卡人:</label>
				<div class="controls">
					<form:input path="cardName" class="required" htmlEscape="false" maxlength="20"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">手续费:</label>
				<div class="controls">
					<form:input path="fee" maxlength="5" number="3,2" htmlEscape="false" class="number required"/>
					<span class="help-inline"><font color="red">*</font> </span>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">备注:</label>
				<div class="controls">
					<form:textarea path="remarks" htmlEscape="false" rows="3" maxlength="200" class="input-xlarge"/>
				</div>
			</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:office:save"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>